/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaCategoria.java
 *
 * Created on 05/04/2011, 09:32:38 PM
 */

package vistas;

import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JTextField;
import controladores.ControladorCategoria;
/**
 *
 * @author usuario
 */
public class VistaCategoria extends javax.swing.JFrame {

    private Vector<JTextField> textos;
    private Vector<JButton> botones;
    private ControladorCategoria control;

    /** Creates new form VistaCategoria */
    public VistaCategoria() {
        initComponents();
        botones = new Vector<JButton>();
        botones.add(btnSalir);
        botones.add(btnConsultar);
        botones.add(btnGenerar);
        botones.add(btnRegistrar);
        botones.add(btnCancelar);

        textos = new Vector<JTextField>();

        textos.add(txtCodigo);
        textos.add(txtDescripcion);

        control= new ControladorCategoria(this);
        btnCancelar.setActionCommand("Cancelar");
        btnConsultar.setActionCommand("Consultar");
        btnRegistrar.setActionCommand("Registrar");
        btnSalir.setActionCommand("Salir");
        btnGenerar.setActionCommand("Generar");
        for (JButton boton : botones) {
            boton.addActionListener(control);
        }
    }


     public boolean validarVacios(){
        for (JTextField texto : textos)
            if(texto.getText().isEmpty())
                return false;
        return true;
    }

     public void cancelar(){
        for (JTextField texto : textos){
            texto.setEditable(true);
            texto.setText("");
        }
        txtCodigo.setEditable(true);
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public JTextField getTxtDescripcion() {
        return txtDescripcion;
    }
     



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnRegistrar = new javax.swing.JButton();
        btnConsultar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnGenerar = new javax.swing.JButton();
        txtDescripcion = new javax.swing.JTextField();
        txtCodigo = new javax.swing.JTextField();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Categorias");
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        jLabel1.setText("Descripcion:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(80, 110, 100, 18);

        jLabel2.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        jLabel2.setText("Codigo:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(80, 50, 60, 18);

        btnRegistrar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnRegistrar.setText("Registrar");
        btnRegistrar.setPreferredSize(new java.awt.Dimension(80, 30));
        getContentPane().add(btnRegistrar);
        btnRegistrar.setBounds(20, 190, 120, 30);

        btnConsultar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnConsultar.setText("Consultar");
        getContentPane().add(btnConsultar);
        btnConsultar.setBounds(150, 190, 120, 30);

        btnCancelar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setPreferredSize(new java.awt.Dimension(80, 30));
        getContentPane().add(btnCancelar);
        btnCancelar.setBounds(280, 190, 120, 30);

        btnGenerar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnGenerar.setText("Generar");
        getContentPane().add(btnGenerar);
        btnGenerar.setBounds(320, 40, 120, 30);
        getContentPane().add(txtDescripcion);
        txtDescripcion.setBounds(180, 100, 110, 28);

        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });
        getContentPane().add(txtCodigo);
        txtCodigo.setBounds(180, 40, 110, 28);

        btnSalir.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnSalir.setText("Salir");
        getContentPane().add(btnSalir);
        btnSalir.setBounds(410, 190, 120, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-540)/2, (screenSize.height-291)/2, 540, 291);
    }// </editor-fold>//GEN-END:initComponents

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCodigoActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaCategoria().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnGenerar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDescripcion;
    // End of variables declaration//GEN-END:variables

}
